//将测试项目的详情表单清空
function testProjectCleanDetailForm() {
    testProjectDetailEditorForm.reset();
    testProjectDetailEditorForm.testProjectId = null;
    testProjectDetailEditorForm.down('#system').systemId = null;
    testProjectDetailEditorForm.down('#group').groupId = null;
    testProjectDetailEditorForm.down('#leadingCadre').leadingCadreId = null;
}

// 获取测试项目的详细信息
function testProjectGetDetail(id) {
    var result;
    Ext.Ajax.request({
        url: zuulUrl + '/' + testServiceName + '/testProject/detail/' + id,
        async: false, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
        method: 'get',
        success: function (response, opts) {
            var obj = Ext.decode(response.responseText);
            obj.createDate = obj.createDate.replace('T', '  ');
            result = obj;
        },
        failure: function (response, opts) {
            Ext.Msg.alert('Error', '该功能暂时不可用');
        }
    });
    return result;
}

// 将测试项目的详细信息填充到表单
function testProjectPutDataIntoForm(obj, type) {
    if (type == 0) {//填充老师的表单
        testProjectDetailEditorForm.testProjectId = obj.id;
        testProjectDetailEditorForm.down('#name').setValue(obj.name);
        testProjectDetailEditorForm.down('#system').setValue(obj.systemName);
        testProjectDetailEditorForm.down('#system').systemId = obj.system;
        testProjectDetailEditorForm.down('#group').setValue(obj.groupName);
        testProjectDetailEditorForm.down('#group').groupId = obj.groupId;
        testProjectDetailEditorForm.down('#leadingCadre').setValue(obj.leadingCadreName);
        testProjectDetailEditorForm.down('#leadingCadre').leadingCadreId = obj.leadingCadre;
        testProjectDetailEditorForm.down('#describe').setValue(obj.describe);
        testProjectDetailEditorForm.down('#createDate').setValue(obj.createDate);
    } else {//填充主任的表单
        testProjectDetailForDirectorForm.testProjectId = obj.id;
        testProjectDetailForDirectorForm.down('#name').setValue(obj.name);
        testProjectDetailForDirectorForm.down('#system').setValue(obj.systemName);
        testProjectDetailForDirectorForm.down('#system').systemId = obj.system;
        testProjectDetailForDirectorForm.down('#group').setValue(obj.groupName);
        testProjectDetailForDirectorForm.down('#group').groupId = obj.groupId;
        testProjectDetailForDirectorForm.down('#leadingCadre').setValue(obj.leadingCadreName);
        testProjectDetailForDirectorForm.down('#leadingCadre').leadingCadreId = obj.leadingCadre;
        testProjectDetailForDirectorForm.down('#describe').setValue(obj.describe);
        testProjectDetailForDirectorForm.down('#createDate').setValue(obj.createDate);
    }

}

//点击测项目详细查看详情之后要做的操作
function testProjectSeeDetailClick(record, editorAble) {
    testProjectIsCreate = 0;
    Ext.getCmp('centerRegion').removeAll(false);
    testProjectCleanDetailForm();
    var data = testProjectGetDetail(record.data.id);
    testProjectPutDataIntoForm(data, editorAble ? 0 : 1);//判断要注入哪个表单
    if (editorAble) {
        Ext.getCmp('centerRegion').add(testProjectDetailEditorForm);
        testProjectDetailEditorForm.pattern = 0;//标注这个表单是老师的可编辑表单
    } else {//如果是主任则是用这个表单显示
        Ext.getCmp('centerRegion').add(testProjectDetailForDirectorForm);
        testProjectDetailForDirectorForm.pattern = 1;//标注这个表单是主任的不可编辑表单
    }

}

//保存测试项目
function testProjectSaveDetail() {
    var systemId = testProjectDetailEditorForm.down('#system').systemId;
    var groupId = testProjectDetailEditorForm.down('#group').groupId;
    if (testProjectDetailEditorForm.isValid() && systemId != null && groupId != null) {
        var id;
        if (testProjectIsCreate == 1)
            id = Ext.create("MyApp.data.MyModelX").data.id.replace(/-/g, "");
        else
            id = testProjectDetailEditorForm.testProjectId;
        var object = new Object();
        object['id'] = id;
        object['name'] = testProjectDetailEditorForm.down('#name').getValue();
        object['system'] = systemId;
        object['groupId'] = groupId;
        object['leadingCadre'] = testProjectDetailEditorForm.down('#leadingCadre').leadingCadreId;
        object['describe'] = testProjectDetailEditorForm.down('#describe').getValue();
        Ext.Ajax.request({
            url: zuulUrl + '/' + testServiceName + '/testProject',
            method: testProjectIsCreate == 1 ? 'post' : 'put',
            async: true, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
            defaultXdrContentType: 'application/json',
            jsonData: JSON.stringify(object),
            success: function (response, opts) {
                Ext.Msg.alert("成功", "保存成功");
                testProjectIsCreate = 0;//保存成功说明现在就不是新建状态了
            },
            failure: function (response, opts) {
                var obj = Ext.decode(response.responseText);
                if (obj.code == 401 || obj.code == 402 || obj.code == 403 || obj.code == 406)
                    Ext.Msg.alert("错误", obj.message);
                else
                    Ext.Msg.alert("错误", "该功能暂时不可用！");
            }
        });
    } else
        Ext.Msg.alert('错误', '测试计划信息请填写完全！');
}


//获取测试流程的信息
function getTestProcessData(projectId) {
    var result;
    Ext.Ajax.request({
        url: zuulUrl + '/' + testServiceName + '/testProject/testProcess/' + projectId,
        async: false, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
        method: 'get',
        success: function (response, opts) {
            var obj = null;
            if (response.responseText == "")
                testProcessIsCreate = 1;//如果后台查出来为无,就说明这个测试项目没有测试流程，所以设为新建状态
            else {
                testProcessIsCreate = 0;
                obj = Ext.decode(response.responseText);
            }
            result = obj;
        },
        failure: function (response, opts) {
            Ext.Msg.alert('Error', '该功能暂时不可用');
        }
    });
    return result;
}

//清空测试流程的表单
function testProcessCleanForm(editorAble) {
    testProcessForm.testProjectId = null;
    testProcessForm.testProcessId = null;
    testProcessForm.reset();
    testProcessForm.down('#trqIsInclude').getEl().unmask();
    testProcessForm.down('#designIsInclude').getEl().unmask();
    testProcessForm.down('#runIsInclude').getEl().unmask();
    //testProcessForm.down('#reportIsInclude').getEl().unmask();
    testProjectProcessAndGradeSetReadOnly(!editorAble)//主任的话只能看不能编辑
}

//将从测试流程的数据填充到表单
function testProcessPutDataInto(data, editorAble) {
    if (data != null) {
        testProcessForm.testProcessId = data.id;
        var totalFieldSet = testProcessForm.down('#totalTime');
        var trqFieldSet = testProcessForm.down('#trqIsInclude');
        var designFieldSet = testProcessForm.down('#designIsInclude');
        var runFieldSet = testProcessForm.down('#runIsInclude');
        //var reportFieldSet=testProcessForm.down('#reportIsInclude');
        trqFieldSet.setCollapsed(data.trqIsInclude == 0);
        designFieldSet.setCollapsed(data.designIsInclude == 0);
        runFieldSet.setCollapsed(data.runIsInclude == 0);
        //reportFieldSet.setCollapsed(data.reportIsInclude==0);
        var totalBeginIndex = data.totalBeginTime.indexOf('T');
        var totalEndIndex = data.totalEndTime.indexOf('T');
        totalFieldSet.down('#beginDate').setValue(data.totalBeginTime.substring(0, totalBeginIndex));
        totalFieldSet.down('#beginTime').setValue(data.totalBeginTime.substring(totalBeginIndex + 1, totalBeginIndex + 6));//如果时间的格式不对，取出来就是null
        totalFieldSet.down('#endDate').setValue(data.totalEndTime.substring(0, totalEndIndex));
        totalFieldSet.down('#endTime').setValue(data.totalEndTime.substring(totalEndIndex + 1, totalEndIndex + 6));//如果时间的格式不对，取出来就是null
        totalFieldSet.down('#isNoticeGroupMember').setValue(data.isNoticeGroupMember == 1);
        if (data.trqIsInclude == 1) {
            var beginIndex = data.trqBeginTime.indexOf('T');
            var endIndex = data.trqEndTime.indexOf('T');
            trqFieldSet.down('#beginDate').setValue(data.trqBeginTime.substring(0, beginIndex));
            trqFieldSet.down('#beginTime').setValue(data.trqBeginTime.substring(beginIndex + 1, beginIndex + 6));//如果时间的格式不对，取出来就是null
            trqFieldSet.down('#endDate').setValue(data.trqEndTime.substring(0, endIndex));
            trqFieldSet.down('#endTime').setValue(data.trqEndTime.substring(endIndex + 1, endIndex + 6));//如果时间的格式不对，取出来就是null
            trqFieldSet.down('#isNotice').setValue(data.trqIsNotice == 1);
            if (editorAble && !checkTimeIsFarWay(data.trqEndTime, 5))
                trqFieldSet.getEl().mask('阶段结束前5分钟才能修改');//只有目前距离测试需求结束的时间超过5分钟才能修改
        }
        if (data.designIsInclude == 1) {
            var beginIndex = data.designBeginTime.indexOf('T');
            var endIndex = data.designEndTime.indexOf('T');
            designFieldSet.down('#beginDate').setValue(data.designBeginTime.substring(0, beginIndex));
            designFieldSet.down('#beginTime').setValue(data.designBeginTime.substring(beginIndex + 1, beginIndex + 6));//如果时间的格式不对，取出来就是null
            designFieldSet.down('#endDate').setValue(data.designEndTime.substring(0, endIndex));
            designFieldSet.down('#endTime').setValue(data.designEndTime.substring(endIndex + 1, endIndex + 6));//如果时间的格式不对，取出来就是null
            designFieldSet.down('#isNotice').setValue(data.designIsNotice == 1);
            if (editorAble && !checkTimeIsFarWay(data.designEndTime, 5))
                designFieldSet.getEl().mask('阶段结束前5分钟才能修改');//只有目前距离测试计划结束的时间超过5分钟才能修改
        }
        if (data.runIsInclude == 1) {
            var beginIndex = data.runBeginTime.indexOf('T');
            var endIndex = data.runEndTime.indexOf('T');
            runFieldSet.down('#beginDate').setValue(data.runBeginTime.substring(0, beginIndex));
            runFieldSet.down('#beginTime').setValue(data.runBeginTime.substring(beginIndex + 1, beginIndex + 6));//如果时间的格式不对，取出来就是null
            runFieldSet.down('#endDate').setValue(data.runEndTime.substring(0, endIndex));
            runFieldSet.down('#endTime').setValue(data.runEndTime.substring(endIndex + 1, endIndex + 6));//如果时间的格式不对，取出来就是null
            runFieldSet.down('#isNotice').setValue(data.runIsNotice == 1);
            if (editorAble && !checkTimeIsFarWay(data.runEndTime, 5))
                runFieldSet.getEl().mask('阶段结束前5分钟才能修改');//只有目前距离测试执行结束的时间超过5分钟才能修改
        }
        // if(data.reportIsInclude==1){
        // 	var beginIndex=data.reportBeginTime.indexOf('T');
        // 	var endIndex=data.reportEndTime.indexOf('T');
        // 	reportFieldSet.down('#beginDate').setValue(data.reportBeginTime.substring(0,beginIndex));
        // 	reportFieldSet.down('#beginTime').setValue(data.reportBeginTime.substring(beginIndex+1,beginIndex+6));//如果时间的格式不对，取出来就是null
        // 	reportFieldSet.down('#endDate').setValue(data.reportEndTime.substring(0,endIndex));
        // 	reportFieldSet.down('#endTime').setValue(data.reportEndTime.substring(endIndex+1,endIndex+6));//如果时间的格式不对，取出来就是null
        // 	reportFieldSet.down('#isNotice').setValue(data.reportIsNotice==1);
        // 	if(editorAble&&!checkTimeIsFarWay(data.reportEndTime,5))
        // 		reportFieldSet.getEl().mask('阶段结束前5分钟才能修改');//只有目前距离测试报告结束的时间超过5分钟才能修改
        // }
    }
}

//保存测试流程
function testProcessSave() {
    var eachEndTime = new Array();
    var totalFieldSet = testProcessForm.down('#totalTime');
    var trqFieldSet = testProcessForm.down('#trqIsInclude');
    var designFieldSet = testProcessForm.down('#designIsInclude');
    var runFieldSet = testProcessForm.down('#runIsInclude');
    //var reportFieldSet=testProcessForm.down('#reportIsInclude');
    var result = new Object();
    var totalBeginDate = totalFieldSet.down('#beginDate').getValue();
    var totalBeginTime = totalFieldSet.down('#beginTime').getValue();
    var totalEndDate = totalFieldSet.down('#endDate').getValue();
    var totalEndTime = totalFieldSet.down('#endTime').getValue();
    if (totalBeginDate == null || totalBeginTime == null || totalEndDate == null || totalEndTime == null) {//检验总安排的时间是否规范
        Ext.Msg.alert('错误', '测试流程信息请填写完全！');
        return;
    } else {
        var totalBginDateTime = getFormatDateDateTime(totalBeginDate, totalBeginTime);
        var totalEndDateTime = getFormatDateDateTime(totalEndDate, totalEndTime);
        if (!checkProcessTime(totalBginDateTime, totalEndDateTime, testProcessIsCreate == 1))
            return false;
        result['totalBeginTime'] = totalBginDateTime;
        result['totalEndTime'] = totalEndDateTime;
        result['isNoticeGroupMember'] = totalFieldSet.down('#isNoticeGroupMember').getValue() ? 1 : 0;
    }
    if (!trqFieldSet.collapsed) {//如果包括测试需求的话
        result['trqIsInclude'] = 1;
        var beginDate = trqFieldSet.down('#beginDate').getValue();
        var beginTime = trqFieldSet.down('#beginTime').getValue();
        var endDate = trqFieldSet.down('#endDate').getValue();
        var endTime = trqFieldSet.down('#endTime').getValue();
        if (beginDate == null || beginTime == null || endDate == null || endTime == null) {
            Ext.Msg.alert('错误', '测试流程信息请填写完全！');
            return;
        } else {
            var beginDateTime = getFormatDateDateTime(beginDate, beginTime);
            var endDateTime = getFormatDateDateTime(endDate, endTime);
            if (!checkProcessTime(beginDateTime, endDateTime, testProcessIsCreate == 1))
                return false;
            if (!checkTimeIsOrder(totalBginDateTime, beginDateTime)) {
                Ext.Msg.alert('错误', '阶段的时间块应该位于总时间块内！');
                return false;
            }
            result['trqBeginTime'] = beginDateTime;
            result['trqEndTime'] = endDateTime;
            eachEndTime.push(endDateTime);//将结束时间存入数组
            result['trqIsNotice'] = trqFieldSet.down('#isNotice').getValue() ? 1 : 0;
        }
    } else
        result['trqIsInclude'] = 0;
    if (!designFieldSet.collapsed) {//如果包括测试计划的话
        result['designIsInclude'] = 1;
        var beginDate = designFieldSet.down('#beginDate').getValue();
        var beginTime = designFieldSet.down('#beginTime').getValue();
        var endDate = designFieldSet.down('#endDate').getValue();
        var endTime = designFieldSet.down('#endTime').getValue();
        if (beginDate == null || beginTime == null || endDate == null || endTime == null) {
            Ext.Msg.alert('错误', '测试流程信息请填写完全！');
            return;
        } else {
            var beginDateTime = getFormatDateDateTime(beginDate, beginTime);
            var endDateTime = getFormatDateDateTime(endDate, endTime);
            if (!checkProcessTime(beginDateTime, endDateTime, testProcessIsCreate == 1))
                return false;
            if (!checkTimeIsOrder(totalBginDateTime, beginDateTime)) {
                Ext.Msg.alert('错误', '阶段的时间块应该位于总时间块内！');
                return false;
            }
            result['designBeginTime'] = beginDateTime;
            result['designEndTime'] = endDateTime;
            eachEndTime.push(endDateTime);//将结束时间存入数组
            result['designIsNotice'] = designFieldSet.down('#isNotice').getValue() ? 1 : 0;
        }
    } else
        result['designIsInclude'] = 0;
    if (!runFieldSet.collapsed) {//如果包括测试运行的话
        result['runIsInclude'] = 1;
        var beginDate = runFieldSet.down('#beginDate').getValue();
        var beginTime = runFieldSet.down('#beginTime').getValue();
        var endDate = runFieldSet.down('#endDate').getValue();
        var endTime = runFieldSet.down('#endTime').getValue();
        if (beginDate == null || beginTime == null || endDate == null || endTime == null) {
            Ext.Msg.alert('错误', '测试流程信息请填写完全！');
            return;
        } else {
            var beginDateTime = getFormatDateDateTime(beginDate, beginTime);
            var endDateTime = getFormatDateDateTime(endDate, endTime);
            if (!checkProcessTime(beginDateTime, endDateTime, testProcessIsCreate == 1))
                return false;
            if (!checkTimeIsOrder(totalBginDateTime, beginDateTime)) {
                Ext.Msg.alert('错误', '阶段的时间块应该位于总时间块内！');
                return false;
            }
            result['runBeginTime'] = beginDateTime;
            result['runEndTime'] = endDateTime;
            eachEndTime.push(endDateTime);//将结束时间存入数组
            result['runIsNotice'] = runFieldSet.down('#isNotice').getValue() ? 1 : 0;
        }
    } else
        result['runIsInclude'] = 0;
    // if(!reportFieldSet.collapsed){//如果包括测试报告的话
    // 	result['reportIsInclude']=1;
    // 	var beginDate=reportFieldSet.down('#beginDate').getValue();
    // 	var beginTime=reportFieldSet.down('#beginTime').getValue();
    // 	var endDate=reportFieldSet.down('#endDate').getValue();
    // 	var endTime=reportFieldSet.down('#endTime').getValue();
    // 	if(beginDate==null||beginTime==null||endDate==null||endTime==null){
    // 		Ext.Msg.alert('错误', '测试流程信息请填写完全！');
    // 		return;
    // 	}else{
    // 		var beginDateTime=getFormatDateDateTime(beginDate,beginTime);
    // 		var endDateTime=getFormatDateDateTime(endDate,endTime);
    // 		if(!checkProcessTime(beginDateTime,endDateTime,testProcessIsCreate==1))
    // 			return false;
    // 		if(!checkTimeIsOrder(totalBginDateTime,beginDateTime)){
    // 			Ext.Msg.alert('错误', '阶段的时间块应该位于总时间块内！');
    // 			return false;
    // 		}
    // 		result['reportBeginTime']=beginDateTime;
    // 		result['reportEndTime']=endDateTime;
    // 		result['reportIsNotice']=reportFieldSet.down('#isNotice').getValue()?1:0;
    // 	}
    // }else
    // 	result['reportIsInclude']=0;
    for (var i = 0, length = eachEndTime.length; i < length; i++) {
        for (var j = i + 1; j < length; j++) {
            if (checkTimeIsSame(eachEndTime[i], eachEndTime[j])) {
                Ext.Msg.alert('错误', '各阶段的时间不能相同！');
                return false;
            }
        }
    }
    result['author'] = currentUserId;
    result['toProject'] = testProcessForm.testProjectId;
    var id;
    if (testProcessIsCreate == 1)
        id = Ext.create("MyApp.data.MyModelX").data.id.replace(/-/g, "");
    else
        id = testProcessForm.testProcessId;
    result['id'] = id;
    Ext.Ajax.request({
        url: zuulUrl + '/' + testServiceName + '/testProject/testProcess',
        method: testProcessIsCreate == 1 ? 'post' : 'put',
        async: true, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
        defaultXdrContentType: 'application/json',
        jsonData: JSON.stringify(result),
        success: function (response, opts) {
            Ext.Msg.alert("成功", "保存成功");
            testProcessIsCreate = 0;//保存成功说明现在就不是新建状态了
            testProcessForm.testProcessId = id;//保存完要将Id重新赋值
        },
        failure: function (response, opts) {
            var obj = Ext.decode(response.responseText);
            if (obj.code == 401 || obj.code == 402 || obj.code == 403 || obj.code == 406 || obj.code == 407)
                Ext.Msg.alert("错误", obj.message);
            else
                Ext.Msg.alert("错误", "该功能暂时不可用！");
        }
    });
}

//当点击设计测试计划的流程的按钮时的操作
function testProjectDesignProcessClick(record, editorAble) {
    if (editorAble && record.data.groupId == null) {
        Ext.Msg.alert("错误", "设计流程前要先将此项目交由某个组负责！");
        return false;
    }
    Ext.getCmp('centerRegion').removeAll(false);
    Ext.getCmp('centerRegion').add(testProcessForm);
    testProcessCleanForm(editorAble);
    var data = getTestProcessData(record.data.id);
    testProcessPutDataInto(data, editorAble);
    testProcessForm.testProjectId = record.data.id;
    testProcessForm.pattern = editorAble ? 0 : 1;//标注这个表单是老师还是主任的,用于点击返回的判断
}

//判断这个时间是否符合要求
function checkProcessTime(beginTime, endTime, isCreate) {
    if (isCreate) {//如果是创建的话，就要检验时间是不是都是未来时间
        if (!checkTimeIsFarWay(beginTime, 0) || !checkTimeIsFarWay(endTime, 0)) {
            Ext.Msg.alert("错误", "添加流程的时间项要是未来时间！");
            return false;
        }
    }
    if (!checkTimeIsOrder(beginTime, endTime)) {
        Ext.Msg.alert("错误", "添加流程的开始时间项要早于结束时间项！");
        return false;
    }
    return true;
}

//点击返回之后要进行的操作
function testProjectBackClick(type) {
    Ext.getCmp('centerRegion').removeAll(false);
    Ext.getCmp('westRegion').setHidden(true);
    testProjectStore.reload();
    if (type == 0)
        Ext.getCmp('centerRegion').add(testProjectGrid);
    else
        Ext.getCmp('centerRegion').add(testProjectForUnAbleEditorGrid);
}

//当点击设计测试项目的评分标准制定的按钮时的操作
function testGradeRuleDesignClick(record, editorAble) {
    Ext.getCmp('centerRegion').removeAll(false);
    Ext.getCmp('centerRegion').add(testGradeRuleForm);
    testGradeRuleCleanForm(editorAble);
    var data = getTestGradeRuleData(record.data.id);
    testGradeRulePutDataInto(data);
    testGradeRuleForm.testProjectId = record.data.id;
    testGradeRuleForm.pattern = editorAble ? 0 : 1;//标注这个表单是老师还是主任的,用于点击返回的判断
}

//清空测试评分标准的表单
function testGradeRuleCleanForm(editorAble) {
    testGradeRuleForm.testProjectId = null;
    testGradeRuleForm.testGradeRuleId = null;
    testGradeRuleForm.reset();
//	testGradeRuleForm.down('#trqIsInclude').getEl().unmask();
//	testGradeRuleForm.down('#designIsInclude').getEl().unmask();
//	testGradeRuleForm.down('#runIsInclude').getEl().unmask();
//	testGradeRuleForm.down('#reportIsInclude').getEl().unmask();
//	testGradeRuleForm.down('#isHasOtherGrade').getEl().unmask();
    testGradeRuleForm.down('#isCalculateTeamGrade').setDisabled(false);
//	testGradeRuleForm.down('#isComposeWithTeamGrade').getEl().unmask();
    testProjectProcessAndGradeSetReadOnly(!editorAble)//主任的话只能看不能编辑
}

//获取测试评分标准的详细信息
function getTestGradeRuleData(projectId) {
    var result;
    Ext.Ajax.request({
        url: zuulUrl + '/' + testServiceName + '/testProject/gradeRule/' + projectId,
        async: false, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
        method: 'get',
        success: function (response, opts) {
            var obj = null;
            if (response.responseText == "")
                testGradeRuleIsCreate = 1;//如果后台查出来为无,就说明这个测试项目没有测试评分标准，所以设为新建状态
            else {
                testGradeRuleIsCreate = 0;
                obj = Ext.decode(response.responseText);
            }
            result = obj;
        },
        failure: function (response, opts) {
            Ext.Msg.alert('Error', '该功能暂时不可用');
        }
    });
    return result;
}

//将从测试评分标准的数据填充到表单
function testGradeRulePutDataInto(data) {
    if (data != null) {
        testGradeRuleForm.testGradeRuleId = data.id;
        var trqFieldSet = testGradeRuleForm.down('#trqIsInclude');
        var designFieldSet = testGradeRuleForm.down('#designIsInclude');
        var runFieldSet = testGradeRuleForm.down('#runIsInclude');
        var bugFieldSet = testGradeRuleForm.down('#bugIsInclude');
        //var reportFieldSet=testGradeRuleForm.down('#reportIsInclude');
        var checkOnWorkFieldSet = testGradeRuleForm.down('#isCheckOnWork');
        var otherFieldSet = testGradeRuleForm.down('#isHasOtherGrade');
        var teamFieldSet = testGradeRuleForm.down('#isComposeWithTeamGrade');//设定团队分数在个人总评分占比的FieldSet
        var isCalculateTeamGrade = testGradeRuleForm.down('#isCalculateTeamGrade');//设定团队分数组成的fieldSet
        trqFieldSet.setCollapsed(data.trqIsInclude == 0);
        designFieldSet.setCollapsed(data.designIsInclude == 0);
        runFieldSet.setCollapsed(data.runIsInclude == 0);
        bugFieldSet.setCollapsed(!data.bugIsInclude);
        //reportFieldSet.setCollapsed(data.reportIsInclude==0);
        checkOnWorkFieldSet.setCollapsed(data.isCheckOnWork == 0);
        otherFieldSet.setCollapsed(data.isHasOtherGrade == 0);
        teamFieldSet.setCollapsed(data.isComposeWithTeamGrade == 0);
        isCalculateTeamGrade.setCollapsed(data.isCalculateTeamGrade == 0);
        if (data.trqIsInclude == 1) {
            trqFieldSet.down('#percent').setValue(data.trqPercent);
            trqFieldSet.down('#floors').setValue(data.trqFloors);
        }
        if (data.designIsInclude == 1) {
            designFieldSet.down('#percent').setValue(data.designPercent);
            designFieldSet.down('#floors').setValue(data.designFloors);
        }
        if (data.runIsInclude == 1) {
            runFieldSet.down('#percent').setValue(data.runPercent);
            runFieldSet.down('#floors').setValue(data.runFloors);
        }
        if (data.bugIsInclude) {
            bugFieldSet.down('#percent').setValue(data.runPercent);
            bugFieldSet.down('#floors').setValue(data.runFloors);
        }
        // if(data.reportIsInclude==1){
        // 	reportFieldSet.down('#percent').setValue(data.reportPercent);
        // 	reportFieldSet.down('#floors').setValue(data.reportFloors);
        // }
        if (data.isCheckOnWork == 1) {
            checkOnWorkFieldSet.down('#beginDate').setValue(data.checkBeginDate);
            checkOnWorkFieldSet.down('#endDate').setValue(data.checkEndDate);
            checkOnWorkFieldSet.down('#beginTime').setValue(data.checkBeginTime.substring(0, 5));//如果时间的格式不对，取出来就是null
            checkOnWorkFieldSet.down('#endTime').setValue(data.checkEndTime.substring(0, 5));//如果时间的格式不对，取出来就是null
            checkOnWorkFieldSet.down('#missOneDeduct').setValue(data.checkMissOneDeduct);
            checkOnWorkFieldSet.down('#missDeadTime').setValue(data.checkMissDeadTime);
            checkOnWorkFieldSet.down('#percent').setValue(data.checkPercent);
        }
        if (data.isHasOtherGrade == 1) {
            otherFieldSet.down('#name').setValue(data.otherGradeName);
            otherFieldSet.down('#percent').setValue(data.otherGradePercent);
        }
        if (data.isCalculateTeamGrade == 1) {
            isCalculateTeamGrade.down('#averagePercent').setValue(data.averagePercent);
            isCalculateTeamGrade.down('#trqCoverPercent').setValue(data.trqCoverPercent);
        }
        if (data.isComposeWithTeamGrade == 1)
            teamFieldSet.down('#percent').setValue(data.teamGradePercent);
    }
}

//保存测试评分标准
function testGradeRuleSave() {
    var trqFieldSet = testGradeRuleForm.down('#trqIsInclude');
    var designFieldSet = testGradeRuleForm.down('#designIsInclude');
    var runFieldSet = testGradeRuleForm.down('#runIsInclude');
    var bugFieldSet = testGradeRuleForm.down('#bugIsInclude');
    //var reportFieldSet=testGradeRuleForm.down('#reportIsInclude');
    var checkOnWorkFieldSet = testGradeRuleForm.down('#isCheckOnWork');
    var otherFieldSet = testGradeRuleForm.down('#isHasOtherGrade');
    var teamFieldSet = testGradeRuleForm.down('#isComposeWithTeamGrade');//设定团队分数在个人总评分占比的FieldSet
    var isCalculateTeamGrade = testGradeRuleForm.down('#isCalculateTeamGrade');//设定团队分数组成的fieldSet
    var result = new Object();
    var allPercent = 0;
    if (!trqFieldSet.collapsed) {//如果包括测试需求的话
        result['trqIsInclude'] = 1;
        var percent = trqFieldSet.down('#percent').getValue();
        var floors = trqFieldSet.down('#floors').getValue();
        if (percent == null || floors == null) {
            Ext.Msg.alert('错误', '评分标准信息请填写完全！');
            return;
        } else {
            result['trqPercent'] = percent;
            allPercent = allPercent + percent;
            result['trqFloors'] = floors;
        }
    } else
        result['trqIsInclude'] = 0;
    if (!designFieldSet.collapsed) {//如果包括测试计划的话
        result['designIsInclude'] = 1;
        var percent = designFieldSet.down('#percent').getValue();
        var floors = designFieldSet.down('#floors').getValue();
        if (percent == null || floors == null) {
            Ext.Msg.alert('错误', '评分标准信息请填写完全！');
            return;
        } else {
            result['designPercent'] = percent;
            allPercent = allPercent + percent;
            result['designFloors'] = floors;
        }
    } else
        result['designIsInclude'] = 0;
    if (!runFieldSet.collapsed) {//如果包括测试运行的话
        result['runIsInclude'] = 1;
        var percent = runFieldSet.down('#percent').getValue();
        var floors = runFieldSet.down('#floors').getValue();
        if (percent == null || floors == null) {
            Ext.Msg.alert('错误', '评分标准信息请填写完全！');
            return;
        } else {
            result['runPercent'] = percent;
            allPercent = allPercent + percent;
            result['runFloors'] = floors;
        }
    } else
        result['runIsInclude'] = 0;
    if (!bugFieldSet.collapsed) {//如果包括测试Bug的话
        result['bugIsInclude'] = true;
        var percent = bugFieldSet.down('#percent').getValue();
        var floors = bugFieldSet.down('#floors').getValue();
        if (percent == null || floors == null) {
            Ext.Msg.alert('错误', '评分标准信息请填写完全！');
            return;
        } else {
            result['bugPercent'] = percent;
            allPercent = allPercent + percent;
            result['bugFloors'] = floors;
        }
    } else
        result['bugIsInclude'] = false;
    // if(!reportFieldSet.collapsed){//如果包括测试报告的话
    // 	result['reportIsInclude']=1;
    // 	var percent=reportFieldSet.down('#percent').getValue();
    // 	var floors=reportFieldSet.down('#floors').getValue();
    // 	if(percent==null||floors==null){
    // 		Ext.Msg.alert('错误', '评分标准信息请填写完全！');
    // 		return;
    // 	}else{
    // 		result['reportPercent']=percent;
    // 		allPercent=allPercent+percent;
    // 		result['reportFloors']=floors;
    // 	}
    // }else
    // 	result['reportIsInclude']=0;
    if (!checkOnWorkFieldSet.collapsed) {//如果包括考勤的话
        result['isCheckOnWork'] = 1;
        var beginDate = checkOnWorkFieldSet.down('#beginDate').getValue();
        var endDate = checkOnWorkFieldSet.down('#endDate').getValue();
        var beginTime = checkOnWorkFieldSet.down('#beginTime').getValue() + ':00';
        var endTime = checkOnWorkFieldSet.down('#endTime').getValue() + ':00';
        var missOneDeduct = checkOnWorkFieldSet.down('#missOneDeduct').getValue();
        var missDeadTime = checkOnWorkFieldSet.down('#missDeadTime').getValue();
        var percent = checkOnWorkFieldSet.down('#percent').getValue();
        if (beginDate == null || endDate == null || beginTime == null || endTime == null || missOneDeduct == null || missDeadTime == null || percent == null) {
            Ext.Msg.alert('错误', '评分标准信息请填写完全！');
            return;
        }
        if (!checkTimeIsOrder(beginDate, endDate) || !checkTimeIsOrder(beginTime, endTime)) {
            Ext.Msg.alert('错误', '考勤开始时间要早于结束时间！');
            return;
        }
        result['checkBeginDate'] = getFormatDate(beginDate);
        result['checkEndDate'] = getFormatDate(endDate);
        result['checkBeginTime'] = getFormatTime(beginTime);
        result['checkEndTime'] = getFormatTime(endTime);
        result['checkPercent'] = percent;
        result['checkMissOneDeduct'] = missOneDeduct;
        result['checkMissDeadTime'] = missDeadTime;
        allPercent = allPercent + percent;
    } else
        result['isCheckOnWork'] = 0;
    if (!otherFieldSet.collapsed) {//如果包括其他评分标准的话
        result['isHasOtherGrade'] = 1;
        var name = otherFieldSet.down('#name').getValue();
        var percent = otherFieldSet.down('#percent').getValue();
        if (percent == null || name == null) {
            Ext.Msg.alert('错误', '评分标准信息请填写完全！');
            return;
        } else {
            result['otherGradeName'] = name;
            result['otherGradePercent'] = percent;
            allPercent = allPercent + percent;
        }
    } else
        result['isHasOtherGrade'] = 0;
    if (!isCalculateTeamGrade.collapsed) {//如果要计算团队分数的话
        result['isCalculateTeamGrade'] = 1;
        var trqCoverPercent = isCalculateTeamGrade.down('#trqCoverPercent').getValue();
        var averagePercent = isCalculateTeamGrade.down('#averagePercent').getValue();
        if (trqCoverPercent == null || averagePercent == null) {
            Ext.Msg.alert('错误', '评分标准信息请填写完全！');
            return;
        } else {
            var teamAllPercent = trqCoverPercent + averagePercent;
            if (teamAllPercent != 100) {
                Ext.Msg.alert('错误', '团队评分总比为' + teamAllPercent + '不等于100！');
                return;
            }
            result['trqCoverPercent'] = trqCoverPercent;
            result['averagePercent'] = averagePercent;
        }
    } else
        result['isCalculateTeamGrade'] = 0;
    if (!teamFieldSet.collapsed) {//如果包括团队分数的话
        result['isComposeWithTeamGrade'] = 1;
        var percent = teamFieldSet.down('#percent').getValue();
        if (isCalculateTeamGrade.collapsed) {
            Ext.Msg.alert('错误', '团队评分要纳入评分标准的话请先设置团队评分标准！');
            return;
        }
        if (percent == null) {
            Ext.Msg.alert('错误', '评分标准信息请填写完全！');
            return;
        } else
            result['teamGradePercent'] = percent;
    } else
        result['isComposeWithTeamGrade'] = 0;
    if (allPercent != 100) {
        Ext.Msg.alert('错误', '目前评分总比为' + allPercent + '不等于100！(不包括团队评分占比)');
        return;
    }
    result['author'] = currentUserId;
    result['toProject'] = testGradeRuleForm.testProjectId;
    var id;
    if (testGradeRuleIsCreate == 1)
        id = Ext.create("MyApp.data.MyModelX").data.id.replace(/-/g, "");
    else
        id = testGradeRuleForm.testGradeRuleId;
    result['id'] = id;
    Ext.Ajax.request({
        url: zuulUrl + '/' + testServiceName + '/testProject/gradeRule',
        method: testGradeRuleIsCreate == 1 ? 'post' : 'put',
        async: true, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
        defaultXdrContentType: 'application/json',
        jsonData: JSON.stringify(result),
        success: function (response, opts) {
            Ext.Msg.alert("成功", "保存成功");
            testGradeRuleIsCreate = 0;//保存成功说明现在就不是新建状态了
            testGradeRuleForm.testGradeRuleId = id;//保存完要将Id重新赋值
        },
        failure: function (response, opts) {
            var obj = Ext.decode(response.responseText);
            if (obj.code == 401 || obj.code == 402 || obj.code == 403 || obj.code == 406 || obj.code == 407)
                Ext.Msg.alert("错误", obj.message);
            else
                Ext.Msg.alert("错误", "该功能暂时不可用！");
        }
    });
}

//点击添加项目后的操作
function testProjectAddClick() {
    Ext.getCmp('centerRegion').removeAll(false);
    testProjectIsCreate = 1;
    testProjectCleanDetailForm();
    testProjectDetailEditorForm.pattern = 0;//标注这个表单是老师的可编辑表单
    testProjectDetailEditorForm.down('#leadingCadre').setValue(currentUser);//将当前操作者的名字加在测试项目表单上
    testProjectDetailEditorForm.down('#leadingCadre').leadingCadreId = currentUserId;
    Ext.getCmp('centerRegion').add(testProjectDetailEditorForm);
}

//点击删除项目后的操作
function testProjectDeleteClick() {
    var item = testProjectGrid.getSelectionModel().getSelected();// 得到被选择的行的数组.
    if (item.length == 0)
        Ext.Msg.alert('错误', '请选择要删除的测试项目！');
    else {
        Ext.MessageBox.confirm('删除', '你确定要将该测试项目删除吗', function (btn) {
            if (btn === 'yes') {
                var idArray = new Array();
                for (var i = 0, length = item.items.length; i < length; i++) {
                    idArray.push(item.items[i].data.id);
                }
                Ext.Ajax.request({
                    url: zuulUrl + '/' + testServiceName + '/testProject/delList',
                    method: 'put',
                    params: {
                        ids: idArray
                    },
                    async: true, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
                    success: function (response, opts) {
                        Ext.Msg.alert("成功", "删除成功");
                        for (var i = 0, length = idArray.length; i < length; i++) {
                            testProjectStore.remove(testProjectStore.getById(idArray[i]));
                        }
                    },
                    failure: function (response, opts) {
                        var obj = Ext.decode(response.responseText);
                        if (obj.code == 401 || obj.code == 402 || obj.code == 403 || obj.code == 406)
                            Ext.Msg.alert("错误", obj.message);
                        else
                            Ext.Msg.alert("错误", "该功能暂时不可用！");
                    }
                });
            }
        });
    }
}

//将测试流程和测试评分标准的制定form的所有field设置readOnly
function testProjectProcessAndGradeSetReadOnly(readOnly) {
    var totalFieldSet = testProcessForm.down('#totalTime');
    var trqFieldSet = testProcessForm.down('#trqIsInclude');
    var designFieldSet = testProcessForm.down('#designIsInclude');
    var runFieldSet = testProcessForm.down('#runIsInclude');
    var bugFieldSet = testGradeRuleForm.down('#bugIsInclude');
    //var reportFieldSet=testProcessForm.down('#reportIsInclude');
    totalFieldSet.down('#beginDate').setReadOnly(readOnly);
    totalFieldSet.down('#beginTime').setReadOnly(readOnly);
    totalFieldSet.down('#endDate').setReadOnly(readOnly);
    totalFieldSet.down('#endTime').setReadOnly(readOnly);
    totalFieldSet.down('#isNoticeGroupMember').setReadOnly(readOnly);
    trqFieldSet.down('#beginDate').setReadOnly(readOnly);
    trqFieldSet.down('#beginTime').setReadOnly(readOnly);
    trqFieldSet.down('#endDate').setReadOnly(readOnly);
    trqFieldSet.down('#endTime').setReadOnly(readOnly);
    trqFieldSet.down('#isNotice').setReadOnly(readOnly);
    designFieldSet.down('#beginDate').setReadOnly(readOnly);
    designFieldSet.down('#beginTime').setReadOnly(readOnly);
    designFieldSet.down('#endDate').setReadOnly(readOnly);
    designFieldSet.down('#endTime').setReadOnly(readOnly);
    designFieldSet.down('#isNotice').setReadOnly(readOnly);
    runFieldSet.down('#beginDate').setReadOnly(readOnly);
    runFieldSet.down('#beginTime').setReadOnly(readOnly);
    runFieldSet.down('#endDate').setReadOnly(readOnly);
    runFieldSet.down('#endTime').setReadOnly(readOnly);
    runFieldSet.down('#isNotice').setReadOnly(readOnly);
    // reportFieldSet.down('#beginDate').setReadOnly(readOnly);
    // reportFieldSet.down('#beginTime').setReadOnly(readOnly);
    // reportFieldSet.down('#endDate').setReadOnly(readOnly);
    // reportFieldSet.down('#endTime').setReadOnly(readOnly);
    // reportFieldSet.down('#isNotice').setReadOnly(readOnly);
    //*******************测试项目评分标准*******************//
    trqFieldSet = testGradeRuleForm.down('#trqIsInclude');
    designFieldSet = testGradeRuleForm.down('#designIsInclude');
    runFieldSet = testGradeRuleForm.down('#runIsInclude');
    //reportFieldSet=testGradeRuleForm.down('#reportIsInclude');
    var checkOnWorkFieldSet = testGradeRuleForm.down('#isCheckOnWork');
    var otherFieldSet = testGradeRuleForm.down('#isHasOtherGrade');
    var teamFieldSet = testGradeRuleForm.down('#isComposeWithTeamGrade');//设定团队分数在个人总评分占比的FieldSet
    var isCalculateTeamGrade = testGradeRuleForm.down('#isCalculateTeamGrade');//设定团队分数组成的fieldSet
    trqFieldSet.down('#percent').setReadOnly(readOnly);
    trqFieldSet.down('#floors').setReadOnly(readOnly);
    designFieldSet.down('#percent').setReadOnly(readOnly);
    designFieldSet.down('#floors').setReadOnly(readOnly);
    runFieldSet.down('#percent').setReadOnly(readOnly);
    runFieldSet.down('#floors').setReadOnly(readOnly);
    bugFieldSet.down('#percent').setReadOnly(readOnly);
    bugFieldSet.down('#floors').setReadOnly(readOnly);
    // reportFieldSet.down('#percent').setReadOnly(readOnly);
    // reportFieldSet.down('#floors').setReadOnly(readOnly);
    checkOnWorkFieldSet.down('#beginDate').setReadOnly(readOnly);
    checkOnWorkFieldSet.down('#endDate').setReadOnly(readOnly);
    checkOnWorkFieldSet.down('#beginTime').setReadOnly(readOnly);
    checkOnWorkFieldSet.down('#endTime').setReadOnly(readOnly);
    checkOnWorkFieldSet.down('#missOneDeduct').setReadOnly(readOnly);
    checkOnWorkFieldSet.down('#missDeadTime').setReadOnly(readOnly);
    checkOnWorkFieldSet.down('#percent').setReadOnly(readOnly);
    otherFieldSet.down('#name').setReadOnly(readOnly);
    otherFieldSet.down('#percent').setReadOnly(readOnly);
    isCalculateTeamGrade.down('#averagePercent').setReadOnly(readOnly);
    isCalculateTeamGrade.down('#trqCoverPercent').setReadOnly(readOnly);
    teamFieldSet.down('#percent').setReadOnly(readOnly);
}